<?php
include dirname(dirname(dirname(__FILE__))).'/include/user-verify.php';
include dirname(__FILE__).'/functions.php';

$to_user_id = $_SESSION['user_id'];
$exchange_item = getExchangeByToUserId($to_user_id);
if($exchange_item==NULL) {
	echo 'invalid argument';
	exit();
}
$from_user_id = $exchange_item['from_user_id'];

$conn = get_db_conn();
$table = json_decode($exchange_item['table_content'],true);
for($i=1;$i<=7;$i++) {
	foreach(range('a', 'f') as $item) {
		if($table[$i][$item]=="")continue;
		if($table[$i][$item]<0)$table[$i][$item]=-$table[$i][$item];
	}
}
updateCurDutyTable(json_encode($table));
$sql = 'update user set exchange_status = 0 where id = '.$to_user_id.';';
mysql_query($sql,$conn) or die("db error");
$sql = 'update user set exchange_status = 3 where id = '.$from_user_id.';';
mysql_query($sql,$conn) or die("db errror");

echo '<script>alert("你已接受对方换班申请，对应的值班时间将会改变，请查询值班表进行核实！");
		window.location="show-duty-table.php";</script>';
